#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1010;

int n, m;
int w[N], res[N];

inline void solution()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> w[i];
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    while (v.size() > 1)
    {
        vector<int> next;
        // 遍历组 向上取整
        int loop = v.size() % m == 0 ? v.size() / m : v.size() / m + 1;
        for (int i = 0; i < loop; i++)
        {
            // 遍历每一组
            int k = -1;
            for (int j = i * m; j < min((i + 1) * m, (int)v.size()); j++)
                if (j == i * m || w[v[j]] > w[v[k]])
                    k = j;
            for (int j = i * m; j < min((i + 1) * m, (int)v.size()); j++)
                if (j == k)
                    next.push_back(v[j]);
                else
                    res[v[j]] = loop + 1;
        }
        v = next;
    }
    res[v[0]] = 1;
    cout << res[0];
    for (int i = 1; i < n; i++)
        cout << " " << res[i];
    cout << endl;
    return;
}

int main()
{
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}